import 'package:flutter/material.dart';
import 'package:gzx_dropdown_menu/gzx_dropdown_menu.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBImageStyle/YBImageStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBCityNameModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBMiShuTongListModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBWorkTaiModule/YBZhuanShuYingYongPage/YBMiShuProvider/YBMiShuTongProvider.dart';

import 'YBMiShuTongShangJiKuSubPage.dart';


class YBMiShuTongYiHuoShangJiPage extends StatefulWidget {
  @override
  _YBMiShuTongYiHuoShangJiPageState createState() => _YBMiShuTongYiHuoShangJiPageState();
}

class _YBMiShuTongYiHuoShangJiPageState extends State<YBMiShuTongYiHuoShangJiPage> {

  GZXDropdownMenuController _dropdownMenuController = GZXDropdownMenuController();

  GlobalKey _stackKey = GlobalKey();

  String selectStr;

  String cityNameStr;


  @override
  Widget build(BuildContext context) {
    return Container(
      child:Scaffold(
        appBar: AppBar(
          elevation: 0,
          title: Container(
            child: Text(YBChineseText.workTaiYiHuoShangJiTitle,style: YBTextStyle.TextStyle30313320Medium,),
          ),
        ),
        body: MultiProvider(
          providers:[
            ChangeNotifierProvider(
              create:(context) =>YBMiShuTongYiHuoShangJiManangerListProvider()..getMiShuTongShangJuKuDataList(1,isSecretary: "1"),
            ),
            ChangeNotifierProvider(create: (context) => YBMiShuTongShangJiKuShaiXuanProvider()..getMiShuTongShangJuKuShaiXuan()),
          ],
          child: Stack(
            key: _stackKey,
            children: [
              Expanded(
                child:Column(
                  children: [
                    Container(
                      child:GZXDropDownHeader(
                        stackKey: _stackKey,
                        items: [
                          GZXDropDownHeaderItem(YBChineseText.homeTextAddress),
                          GZXDropDownHeaderItem(YBChineseText.workTaiAllShiWuTitle),
                        ],
                        borderColor: YBColor.white,
                        controller: _dropdownMenuController,
                        style:YBTextStyle.TextStyle18181812Medium,
                        dropDownStyle: YBTextStyle.TextStyle2D69E012Medium,
                      ),
                    ),
                    Expanded(
                      child: Consumer<YBMiShuTongYiHuoShangJiManangerListProvider>(
                          builder:(context,shangJiManager,child){
                            return SmartRefresher(
                              controller:shangJiManager.easyfresh,
                              enablePullDown: true,
                              enablePullUp: true,
                              onLoading:() async {
                                shangJiManager.loadData(isSecretary: "1");
                              },
                              onRefresh:()async {
                                shangJiManager.getRefresh(isSecretary: "1");
                              },
                              child: CustomScrollView(
                                slivers: [
                                  SliverList(
                                    delegate:SliverChildBuilderDelegate(
                                          (BuildContext context,int index){
                                        YBMiShuTongListModel miShuTongListModel = shangJiManager.shangJiManangerModelList[index];
                                        return YBMiShuTongShangJiKuSubPage(timeStr: miShuTongListModel.getTime,addressStr:miShuTongListModel.request.address,contentStr: miShuTongListModel.request.requestTag,shengYuStr: 10000.toString(),sysCode: miShuTongListModel.sysCode,requestCode: miShuTongListModel.requestCode,type: 2,);
                                      },childCount: shangJiManager.shangJiManangerModelList.length,
                                    ),
                                  ),
                                ],
                              ),
                            );
                          }
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                child: Consumer<YBMiShuTongShangJiKuShaiXuanProvider>(
                    builder: (context,dataList,child){

                      return GZXDropDownMenu(
                        controller: _dropdownMenuController,
                        animationMilliseconds: 300,
                        dropdownMenuChanging: (isShow,index){

                        },
                        dropdownMenuChanged: (isShow,index){

                        },
                        menus: [
                          GZXDropdownMenuBuilder(dropDownWidget: _buildConditionListWidget(1,cityNameList: dataList.quanGuoCityNameList), dropDownHeight: YBTextStyle.adapterSize180),
                          GZXDropdownMenuBuilder(dropDownWidget: _buildConditionInfoListWidget(2,stringList: dataList.transcationList), dropDownHeight: YBTextStyle.adapterSize180),
                        ],
                      );
                    }
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }


  _buildConditionListWidget(int index,{List<YBCityNameModel> cityNameList,List<String> stringList}) {

    return ListView.separated(
      shrinkWrap: true,
      scrollDirection: Axis.vertical,
      itemCount: cityNameList.length,
      // item 的个数
      separatorBuilder: (BuildContext context, int index) => Divider(height: 1.0),
      // 添加分割线
      itemBuilder: (BuildContext context, int index) {
        YBCityNameModel cityNameModel = cityNameList[index];
        return Container(
          child: InkWell(
            child: Container(
              height: YBTextStyle.adapterSize40,
              child: Padding(
                padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                child: Align(
                  alignment: Alignment.centerLeft,
                  child: Text(
                    '${cityNameModel.provinceName}-${cityNameModel.cityName}-${cityNameModel.areaName}',
                    style: YBTextStyle.TextStyle64646414,
                  ),
                ),
              ),
            ),
            onTap: () async {
              setState(() {
                cityNameStr = cityNameModel.cityName;
                _dropdownMenuController.hide();
              });
            },
          ),
        );
      },
    );
  }

  _buildConditionInfoListWidget(int index,{List<YBCityNameModel> cityNameList,List<String> stringList}) {

    return ListView.separated(
      shrinkWrap: true,
      scrollDirection: Axis.vertical,
      itemCount: stringList.length,
      // item 的个数
      separatorBuilder: (BuildContext context, int index) => Divider(height: 1.0),
      // 添加分割线
      itemBuilder: (BuildContext context, int index) {
        String stringListModel = stringList[index];
        return Container(
          child: InkWell(
            child: Container(
              height: YBTextStyle.adapterSize40,
              child: Padding(
                padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                child: Align(
                  alignment: Alignment.centerLeft,
                  child: Text(
                    '$stringListModel'??"",
                    style: YBTextStyle.TextStyle64646414,
                  ),
                ),
              ),
            ),
            onTap: () async {
              setState(() {
                selectStr = stringListModel;
                _dropdownMenuController.hide();
              });
            },
          ),
        );
      },
    );
  }


}


